package com.bm.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bm.domain.Provider;
import com.bm.service.ProviderService;

@Controller
public class ProviderController {
	
	@Autowired
	private ProviderService providerService;
	
	@RequestMapping("/findAllPro.action")
	public @ResponseBody Map<String, Object> findAllPro(){
		Map<String, Object> map = new HashMap<String, Object>();
		List<Provider> pros = providerService.findAllProvider();
		map.put("pros", pros);
		return map;
	}
	
	@RequestMapping("/findProvider.action")
	public @ResponseBody Map<String, Object> findProvider(String proName, String proDesc){
		Provider pro = new Provider();
		pro.setProName("%"+proName+"%");
		pro.setDescription("%"+proDesc+"%");
		System.out.println(pro.getDescription());
		System.out.println(pro.getProName());
		Map<String, Object> map = new HashMap<String, Object>();
		List<Provider> pros = providerService.findProvider(pro);
		map.put("pros", pros);
		return map;
	}
	
	@RequestMapping("/addProvider.action")
	public String addProvider(Provider pro){
		providerService.addProvider(pro);
		return "redirect:providerAdmin.jsp";
	}
}
